package com.sfh.base.ui;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.view.View;

import com.sfh.base.mvp.IView;
import com.sfh.base.ui.dialog.AppStyleView;
import com.sfh.base.ui.dialog.IAlertTemple;
/**
 * 功能描述:统一Activity样式
 *
 * @author SunFeihu 孙飞虎
 * @company 中储南京智慧物流科技有限公司
 * @copyright （版权）中储南京智慧物流科技有限公司所有
 * @date 2017/7/5
 */
abstract class UIStyleActivity extends FragmentActivity implements IView {
    //对话框句柄
    protected IView viewProxy = null;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {

        super.onCreate (savedInstanceState);
        this.viewProxy = onCreateStyleDialog ();
    }

    @Override
    public void setContentView(@LayoutRes int layoutResID) {

        super.setContentView (layoutResID);


    }

    @Override
    public void finish() {

        this.hideLoading ();
        this.hideDialog ();
        super.finish ();
    }

    //BaseActivity
    public <T extends View> T $(@IdRes int resId){
        return (T)super.findViewById(resId);
    }


    //创建对话框句柄
    protected IView onCreateStyleDialog() {

        return new AppStyleView (this);
    }


    @Override
    public void showLoading(String message, boolean cancelAble, boolean... isBgColor) {

        if ( this.viewProxy == null ||  this.isFinishing () ) {
            return;
        }

        this.viewProxy.showLoading (message, cancelAble,isBgColor);
    }

    @Override
    public void hideLoading() {

        if ( this.viewProxy == null ||  this.isFinishing ()) {
            return;
        }
        this.viewProxy.hideLoading ();
    }

    @Override
    public void showDialog(IAlertTemple alert, boolean cancelAble) {

        if ( this.viewProxy == null ||  this.isFinishing ()) {
            return;
        }
        this.viewProxy.showDialog (alert, cancelAble);
    }

    @Override
    public void hideDialog() {

        if ( this.viewProxy == null ||  this.isFinishing ()) {
            return;
        }
        this.viewProxy.hideDialog ();
    }

    @Override
    public void showToast(String message, int ms, int... gravity) {

        if ( this.viewProxy == null ||  this.isFinishing ()) {
            return;
        }
        this.viewProxy.showToast (message, ms, gravity);
    }
}
